
package com.epfresh.supplier.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.epfresh.api.widget.CommonInputItem;
import com.epfresh.supplier.R;

import java.util.Map;

import multitype.ItemViewBinder;
import multitype.OnRecyclerViewItemClickListener;

public class OrderTrackSimpleViewBinder
        extends ItemViewBinder<Pair<String, String>, OrderTrackSimpleViewBinder.ViewHolder> implements View.OnClickListener {


    OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;


    public OnRecyclerViewItemClickListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_order_track_simple, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Pair<String, String> post) {

        holder.setData(post);

        int position = getPosition(holder);
        if (position == 0){
            holder.commonInputItem.setTopLineVisible(false);
        }
    }


    @Override
    public void onClick(View v) {

        Object tag = v.getTag(R.id.item_key_position);
        if (tag != null && tag instanceof Integer) {
            int position = (int) tag;
            Object o = v.getTag(R.id.item_key_status);


            switch (v.getId()) {
                case R.id.tv_product_new:

                    break;

                default:
                    if (onRecyclerViewItemClickListener != null && o instanceof Map) {
                        onRecyclerViewItemClickListener.onItemClick(v, position, o);
                    }
                    break;
            }


        }
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        CommonInputItem commonInputItem;

        ViewHolder(@NonNull View itemView) {
            super(itemView);

            commonInputItem = (CommonInputItem) itemView;


        }


        void setData(Pair<String, String> post) {

            commonInputItem.setTitleText(post.first);
            commonInputItem.setContentText(post.second);

            commonInputItem.setTopLineVisible(true);
            commonInputItem.setBottomLineVisible(false);
        }


    }
}
